﻿using MapMaker.Engine.CoreCommon;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MapMaker.Engine.Model.VXAce;
using System.Collections;
using Microsoft.Scripting.Hosting;

namespace MapMaker.Engine.Model.VXAce
{
    public class Manager<T> : IImport<T>
    {
        private static Dictionary<Type, Func<ScriptEngine, dynamic, IEnumerable>> IMPORT = new Dictionary<Type, Func<ScriptEngine, dynamic, IEnumerable>>();
        private static Dictionary<Type, Func<IObjectManager, IEnumerable, IEnumerable<dynamic>>> EXPORT = new Dictionary<Type, Func<IObjectManager, IEnumerable, IEnumerable<dynamic>>>();
        static Manager()
        {
            IMPORT.Add(typeof(RPG_Actor), (e,o) => RPG.Import<RPG_Actor>(e,o));
            IMPORT.Add(typeof(RPG_Animation), (e,o) => RPG.Import<RPG_Animation>(e,o));
            IMPORT.Add(typeof(RPG_Armor), (e,o) => RPG.Import<RPG_Armor>(e,o));
            IMPORT.Add(typeof(RPG_AudioFile), (e,o) => RPG.Import<RPG_AudioFile>(e,o));
            IMPORT.Add(typeof(RPG_BaseItem), (e,o) => RPG.Import<RPG_BaseItem>(e,o));
            IMPORT.Add(typeof(RPG_BGM), (e,o) => RPG.Import<RPG_BGM>(e,o));
            IMPORT.Add(typeof(RPG_BGS), (e,o) => RPG.Import<RPG_BGS>(e,o));
            IMPORT.Add(typeof(RPG_Class), (e,o) => RPG.Import<RPG_Class>(e,o));
            IMPORT.Add(typeof(RPG_Color), (e,o) => RPG.Import<RPG_Color>(e,o));
            IMPORT.Add(typeof(RPG_CommonEvent), (e,o) => RPG.Import<RPG_CommonEvent>(e,o));
            IMPORT.Add(typeof(RPG_Enemy), (e,o) => RPG.Import<RPG_Enemy>(e,o));
            IMPORT.Add(typeof(RPG_EquipItem), (e,o) => RPG.Import<RPG_EquipItem>(e,o));
            IMPORT.Add(typeof(RPG_Event), (e,o) => RPG.Import<RPG_Event>(e,o));
            IMPORT.Add(typeof(RPG_EventCommand), (e,o) => RPG.Import<RPG_EventCommand>(e,o));
            IMPORT.Add(typeof(RPG_Item), (e,o) => RPG.Import<RPG_Item>(e,o));
            IMPORT.Add(typeof(RPG_Map), (e,o) => RPG.Import<RPG_Map>(e,o));
            IMPORT.Add(typeof(RPG_MapInfo), (e,o) => RPG.Import<RPG_MapInfo>(e,o));
            IMPORT.Add(typeof(RPG_ME), (e,o) => RPG.Import<RPG_ME>(e,o));
            IMPORT.Add(typeof(RPG_MoveCommand), (e,o) => RPG.Import<RPG_MoveCommand>(e,o));
            IMPORT.Add(typeof(RPG_MoveRoute), (e,o) => RPG.Import<RPG_MoveRoute>(e,o));
            IMPORT.Add(typeof(RPG_Rect), (e,o) => RPG.Import<RPG_Rect>(e,o));
            IMPORT.Add(typeof(RPG_SE), (e,o) => RPG.Import<RPG_SE>(e,o));
            IMPORT.Add(typeof(RPG_Skill), (e,o) => RPG.Import<RPG_Skill>(e,o));
            IMPORT.Add(typeof(RPG_State), (e,o) => RPG.Import<RPG_State>(e,o));
            IMPORT.Add(typeof(RPG_System), (e,o) => RPG.Import<RPG_System>(e,o));
            IMPORT.Add(typeof(RPG_Table), (e,o) => RPG.Import<RPG_Table>(e,o));
            IMPORT.Add(typeof(RPG_Tileset), (e,o) => RPG.Import<RPG_Tileset>(e,o));
            IMPORT.Add(typeof(RPG_Tone), (e,o) => RPG.Import<RPG_Tone>(e,o));
            IMPORT.Add(typeof(RPG_Troop), (e,o) => RPG.Import<RPG_Troop>(e,o));
            IMPORT.Add(typeof(RPG_UsableItem), (e,o) => RPG.Import<RPG_UsableItem>(e,o));
            IMPORT.Add(typeof(RPG_Weapon), (e,o) => RPG.Import<RPG_Weapon>(e,o));

            EXPORT.Add(typeof(RPG_Actor), (f,o) => RPG_Actor.Export(f,o));
            EXPORT.Add(typeof(RPG_Animation), (f,o) => RPG_Animation.Export(f,o));
            EXPORT.Add(typeof(RPG_Armor), (f,o) => RPG_Armor.Export(f,o));
            EXPORT.Add(typeof(RPG_AudioFile), (f,o) => RPG_AudioFile.Export(f,o));
            EXPORT.Add(typeof(RPG_BaseItem), (f,o) => RPG_BaseItem.Export(f,o));
            EXPORT.Add(typeof(RPG_BGM), (f,o) => RPG_BGM.Export(f,o));
            EXPORT.Add(typeof(RPG_BGS), (f,o) => RPG_BGS.Export(f,o));
            EXPORT.Add(typeof(RPG_Class), (f,o) => RPG_Class.Export(f,o));
            EXPORT.Add(typeof(RPG_Color), (f,o) => RPG_Color.Export(f,o));
            EXPORT.Add(typeof(RPG_CommonEvent), (f,o) => RPG_CommonEvent.Export(f,o));
            EXPORT.Add(typeof(RPG_Enemy), (f,o) => RPG_Enemy.Export(f,o));
            EXPORT.Add(typeof(RPG_EquipItem), (f,o) => RPG_EquipItem.Export(f,o));
            EXPORT.Add(typeof(RPG_Event), (f,o) => RPG_Event.Export(f,o));
            EXPORT.Add(typeof(RPG_EventCommand), (f,o) => RPG_EventCommand.Export(f,o));
            EXPORT.Add(typeof(RPG_Item), (f,o) => RPG_Item.Export(f,o));
            EXPORT.Add(typeof(RPG_Map), (f,o) => RPG_Map.Export(f,o));
            EXPORT.Add(typeof(RPG_MapInfo), (f,o) => RPG_MapInfo.Export(f,o));
            EXPORT.Add(typeof(RPG_ME), (f,o) => RPG_ME.Export(f,o));
            EXPORT.Add(typeof(RPG_MoveCommand), (f,o) => RPG_MoveCommand.Export(f,o));
            EXPORT.Add(typeof(RPG_MoveRoute), (f,o) => RPG_MoveRoute.Export(f,o));
            EXPORT.Add(typeof(RPG_Rect), (f,o) => RPG_Rect.Export(f,o));
            EXPORT.Add(typeof(RPG_SE), (f,o) => RPG_SE.Export(f,o));
            EXPORT.Add(typeof(RPG_Skill), (f,o) => RPG_Skill.Export(f,o));
            EXPORT.Add(typeof(RPG_State), (f,o) => RPG_State.Export(f,o));
            EXPORT.Add(typeof(RPG_System), (f,o) => RPG_System.Export(f,o));
            EXPORT.Add(typeof(RPG_Table), (f,o) => RPG_Table.Export(f,o));
            EXPORT.Add(typeof(RPG_Tileset), (f,o) => RPG_Tileset.Export(f,o));
            EXPORT.Add(typeof(RPG_Tone), (f,o) => RPG_Tone.Export(f,o));
            EXPORT.Add(typeof(RPG_Troop), (f,o) => RPG_Troop.Export(f,o));
            EXPORT.Add(typeof(RPG_UsableItem), (f,o) => RPG_UsableItem.Export(f,o));
            EXPORT.Add(typeof(RPG_Weapon), (f,o) => RPG_Weapon.Export(f,o));
        }


        public IEnumerable<T> Import(ScriptEngine engine, dynamic variable)
        {
            return (IEnumerable<T>)IMPORT[typeof(T)](engine,variable);
        }
    }
}
